import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test2 {


    public static void main(String[] args) {
        String[] words = {"abc","this","this","world","world","world","def"};
        Map<String,Integer> map = countWord(words);
        Set<Map.Entry<String, Integer>> entryset = map.entrySet();
        for(Map.Entry<String, Integer> entry : entryset){
            System.out.println("key:" + entry.getKey() + " value:" + entry.getValue());
        }
    }

    //记录一篇文章中单词的出现的次数
    public static Map<String,Integer> countWord(String[] words) {
        Map<String, Integer> map = new HashMap<>();
        for (String s : words) {
            if (map.get(s) == null) {
                map.put(s, 1);
            } else {
                int val = map.get(s);
                map.put(s, val + 1);
            }
        }
        return map;
    }

    public static void main2(String[] args) {
        HashBacket2<String,Integer> hashBacket2 = new HashBacket2();
        hashBacket2.push("hello",1);
        hashBacket2.push("world",2);

    }
    public static void main1(String[] args){
        HashBacket hashBacket = new HashBacket();
        hashBacket.push(1,9);
        hashBacket.push(11,9);
        hashBacket.push(3,9);
        hashBacket.push(13,9);
        hashBacket.push(15,9);
        hashBacket.push(5,9);
        hashBacket.push(7,9);
        hashBacket.push(9,9);
    }
}
